<template>
  <div class="app-container">
    <!-- 入库单数据 -->
    <el-row>
      <el-col class="card-box">
        <el-card>
          <el-form
            :model="queryBillParams"
            ref="queryBillForm"
            :inline="true"
            v-show="showSearch_"
            label-width="75px"
          >
            <el-form-item label="入库单" prop="outInBillNo">
              <el-input
                v-model="queryBillParams.outInBillNo"
                placeholder="请输入订单编号"
                clearable
                size="small"
                @keyup.enter.native="handleBillQuery"
              />
            </el-form-item>
            <el-form-item label="入库原因" prop="outInType">
              <el-select
                v-model="queryBillParams.outInType"
                placeholder="请选择入库原因"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in outInTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="车间" prop="departmentNo">
              <el-select
                v-model="queryBillParams.departmentNo"
                placeholder="请选择车间"
                clearable
                size="small"
              >
                <el-option
                  v-for="item in departmentOptions"
                  :key="item.departmentNo"
                  :label="item.departmentName"
                  :value="item.departmentNo"
                  :disabled="item.status == 1"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="仓库" prop="wareNo">
              <el-select
                v-model="queryBillParams.wareNo"
                placeholder="请选择仓库"
                clearable
                size="small"
              >
                <el-option
                  v-for="item in wareOptions"
                  :key="item.wareNo"
                  :label="item.wareName"
                  :value="item.wareNo"
                  :disabled="item.status == 1"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                type="cyan"
                icon="el-icon-search"
                size="mini"
                @click="handleBillQuery"
                >搜索</el-button
              >
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetBillQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleAddBill"
                v-hasPermi="['material:materialOutInBill:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                icon="el-icon-edit"
                size="mini"
                :disabled="single_"
                @click="handleUpdateBill"
                v-hasPermi="['material:materialOutInBill:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple_"
                @click="handleDeleteBill"
                v-hasPermi="['material:materialOutInBill:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['material:materialOutInBill:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showSearch_"
              @queryTable="getBillList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            :data="materialOutInBillList"
            @selection-change="handleSelectionChange"
            @row-click="handleRowClick"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
              label="入库单号"
              align="center"
              prop="outInBillNo"
            />
            <el-table-column
              label="关联单号"
              align="center"
              prop="originalBillNo"
            />
            <el-table-column
              label="车间编号"
              align="center"
              prop="departmentNo"
            />
            <el-table-column
              label="车间名"
              align="center"
              prop="departmentName"
            />
            <el-table-column label="仓库编号" align="center" prop="wareNo" />
            <el-table-column label="仓库名" align="center" prop="wareName" />
            <el-table-column
              label="订单状态"
              align="center"
              prop="billStatus"
              :formatter="billStatusFormat"
            />
            <el-table-column
              label="入库原因"
              align="center"
              prop="outInType"
              :formatter="outInTypeFormat"
            />
            <el-table-column
              label="入库日期"
              align="center"
              prop="sortDate"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.sortDate, "{y}-{m}-{d}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.createTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column
              label="更新时间"
              align="center"
              prop="updateTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.updateTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdateBill(scope.row)"
                  v-hasPermi="['material:materialOutInBill:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteBill(scope.row)"
                  v-hasPermi="['material:materialOutInBill:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total_ > 0"
            :total="total_"
            :page.sync="queryBillParams.pageNum"
            :limit.sync="queryBillParams.pageSize"
            @pagination="getBillList"
          />

          <div style="position: absolute; height: 30px">
            <div style="margin-top: -20px; position: relative; float: left">
              <label for="">{{ queryParams.toString }}</label>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 入库单明细 -->
    <el-row>
      <el-col class="card-box">
        <el-card>
          <el-form
            :model="queryParams"
            ref="queryForm"
            :inline="true"
            v-show="showSearch"
            label-width="75px"
          >
            <el-form-item label="原料编号" prop="materialNo">
              <el-input
                v-model="queryParams.materialNo"
                placeholder="请输入原料编号"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择状态"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                type="cyan"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['material:materialOutInBilldetail:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['material:materialOutInBilldetail:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['material:materialOutInBilldetail:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['material:materialOutInBilldetail:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            :data="materialOutInBilldetailList"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="自增长列" align="center" prop="rowId" />
            <el-table-column
              label="入库单号"
              align="center"
              prop="outInBillNo"
            />
            <el-table-column label="条形码" align="center" prop="barcode" />
            <el-table-column
              label="原料编号"
              align="center"
              prop="materialNo"
            />
            <el-table-column
              label="原料名称"
              align="center"
              prop="materialName"
            />
            <el-table-column label="规格" align="center" prop="materialSpec" />
            <el-table-column
              label="单位"
              align="center"
              prop="materialUnit"
              :formatter="materialUnitFormat"
            />
            <el-table-column label="计划数量" align="center" prop="planNum" />
            <el-table-column label="单价" align="center" prop="price" />
            <el-table-column
              label="状态"
              align="center"
              prop="status"
              :formatter="statusFormat"
            />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="140"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.createTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column
              label="更新时间"
              align="center"
              prop="updateTime"
              width="140"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.updateTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['material:materialOutInBilldetail:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['material:materialOutInBilldetail:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <!-- 添加或修改原料出入库订单明细管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="outInBillNo">
          <el-input v-model="form.outInBillNo" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="条形码" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入条形码" />
        </el-form-item>

        <el-row>
          <el-col :span="18">
            <el-form-item label="原料编号" prop="materialNo">
              <el-input
                v-model="form.materialNo"
                placeholder="请选择原料"
                v-bind:disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" align="center">
            <el-button type="primary" @click="selectMaterial">选 择</el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="名称" prop="materialName">
              <el-input v-model="form.materialName" v-bind:disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="规格" prop="materialSpec">
              <el-input v-model="form.materialSpec" v-bind:disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="原料类别" prop="materialCategoryName">
              <el-input
                v-model="form.materialCategoryName"
                v-bind:disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="materialUnit">
              <el-input v-model="form.materialUnit" v-bind:disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="计划数量" prop="planNum">
          <el-input v-model="form.planNum" placeholder="请输入计划数量" />
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <SelectMaterialDialog
      v-bind:open="openM"
      v-on:select="handleSelectMaterial"
      v-on:cancel="cancelSelectMaterial"
    >
    </SelectMaterialDialog>
    <!-- 添加或修改原料出入库订单管理对话框 -->
    <el-dialog
      :title="title_"
      :visible.sync="open_"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="formBill"
        :model="formBill"
        :rules="rules_"
        label-width="80px"
      >
        <el-form-item label="车间" prop="departmentNo">
          <el-select
            v-model="formBill.departmentNo"
            placeholder="请选择车间"
          >
            <el-option
              v-for="item in departmentOptions"
              :key="item.departmentNo"
              :label="item.departmentName"
              :value="item.departmentNo"
              :disabled="item.status == 1"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="仓库" prop="wareNo">
          <el-select v-model="formBill.wareNo" placeholder="请选择仓库">
            <el-option
              v-for="item in wareOptions"
              :key="item.wareNo"
              :label="item.wareName"
              :value="item.wareNo"
              :disabled="item.status == 1"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="入库原因" prop="outInType">
          <el-select v-model="formBill.outInType" placeholder="请选择入库原因">
            <el-option
              v-for="dict in outInTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入库日期" prop="sortDate">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="formBill.sortDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择入库日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关联单号" prop="originalBillNo">
          <el-input v-model="formBill.originalBillNo"  />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formBill.remark" type="textarea" />
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBillForm">确 定</el-button>
        <el-button @click="cancelBill">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMaterialOutInBill,
  getMaterialOutInBill,
  delMaterialOutInBill,
  addMaterialOutInBill,
  updateMaterialOutInBill,
  exportMaterialOutInBill
} from "@/api/material/materialOutInBill";
import {
  listMaterialOutInBilldetail,
  getMaterialOutInBilldetail,
  delMaterialOutInBilldetail,
  addMaterialOutInBilldetail,
  updateMaterialOutInBilldetail,
  exportMaterialOutInBilldetail
} from "@/api/material/materialOutInBilldetail";

import { listDepartment } from "@/api/systembasic/department";
import { listWare } from "@/api/systembasic/ware";
import SelectMaterialDialog from "@/components/Simpsense/SelectMaterialDialog";
export default {
  name: "MaterialOutInBill",
  components: { SelectMaterialDialog },
  data() {
    return {
      //==============================================================================
      //明细变量
      openM: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原料出入库订单明细管理表格数据
      materialOutInBilldetailList: [],
      materialUnitOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        outInBillNo: null,
        barcode: null,
        materialNo: null,
        toString: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        outInBillNo: [
          { required: true, message: "订单编号不能为空", trigger: "blur" }
        ],
        materialNo: [
          { required: true, message: "原料编号不能为空", trigger: "blur" }
        ]
      },
      //==============================================================================
      // 遮罩层
      loading: true,
      // 选中数组
      ids_: [],
      // 非单个禁用
      single_: true,
      // 非多个禁用
      multiple_: true,
      // 显示搜索条件
      showSearch_: true,
      // 总条数
      total_: 0,
      // 原料出入库订单管理表格数据
      materialOutInBillList: [],
      // 弹出层标题
      title_: "",
      // 是否显示弹出层
      open_: false,
      // 出入库类型字典
      outInTypeOptions: [],
      departmentOptions: [],
      wareOptions: [],
      // 查询参数
      queryBillParams: {
        pageNum: 1,
        pageSize: 10,
        outInBillNo: null,
        departmentNo: null,
        wareNo: null,
        billType: "03",
        outInType: null
      },
      // 表单参数
      formBill: {},
      // 表单校验
      rules_: {}
    };
  },
  created() {
    this.getBillList();
    listWare().then(response => {
      this.wareOptions = response.rows;
    });
    listDepartment().then(response => {
      this.departmentOptions = response.rows;
    });
    this.getDicts("bill_common_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("smes_unit").then(response => {
      this.materialUnitOptions = response.data;
    });
    this.getDicts("out_in_type").then(response => {
        this.outInTypeOptions=response.data.filter(function(item) {
        if (item.dictValue.startsWith("1.1.")) {
          return item;
        }
      });
    });
  },
  methods: {
    /** 查询原料出入库订单管理列表 */
    getBillList() {
      this.loading = true;
      listMaterialOutInBill(this.queryBillParams).then(response => {
        this.materialOutInBillList = response.rows;
        this.total_ = response.total;
        this.loading = false;
      });
    },
    // 原料单位字典翻译
    materialUnitFormat(row, column) {
      return this.selectDictLabel(this.materialUnitOptions, row.materialUnit);
    },
        // 出入库类型字典翻译
    outInTypeFormat(row, column) {
      return this.selectDictLabel(this.outInTypeOptions, row.outInType);
    },
    // 字典翻译
    billStatusFormat(row, column) {
      switch (row.billStatus) {
        case "01":
          return "等待入库";
        case "02":
          return "完成入库";
        case "03":
          return "作废";
        default:
          return "等待入库";
      }
      return "";
    },
    // 取消按钮
    cancelBill() {
      this.open_ = false;
      this.resetBill();
    },
    // 表单重置
    resetBill() {
      this.formBill = {
        rowId: null,
        outInBillNo: null,
        departmentNo: null,
        originalBillNo: null,
        wareNo: null,
        sortDate: null,
        billType: "03", //01生产领料；02其他出库；03其他入库
        outInType: null, 
        createBy: null,
        createTime: null,
        updateBy: null,
        billStatus: "01", //01;等待入库02完成入库;03作废
        updateTime: null,
        remark: null
      };
      this.resetForm("formBill");
    },
    /** 搜索按钮操作 */
    handleBillQuery() {
      this.queryBillParams.pageNum = 1;
      this.getBillList();
    },
    /** 重置按钮操作 */
    resetBillQuery() {
      this.resetForm("queryBillForm");
      this.handleBillQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids_ = selection.map(item => item.outInBillNo);
      this.single_ = selection.length !== 1;
      this.multiple_ = !selection.length;
    },
    /** 新增按钮操作 */
    handleAddBill() {
      this.resetBill();
      this.open_ = true;
      this.title_ = "添加原料其他入库单管理";
    },
    /** 修改按钮操作 */
    handleUpdateBill(row) {
      this.resetBill();
      const outInBillNo = row.outInBillNo || this.ids_;
      getMaterialOutInBill(outInBillNo).then(response => {
        this.formBill = response.data;
        this.open_ = true;
        this.title_ = "修改原料其他入库单管理";
      });
    },
    /** 提交按钮 */
    submitBillForm() {
      this.$refs["formBill"].validate(valid => {
        if (valid) {
          if (this.formBill.outInBillNo != null) {
            updateMaterialOutInBill(this.formBill).then(response => {
              this.msgSuccess("修改成功");
              this.open_ = false;
              this.getBillList();
            });
          } else {
            addMaterialOutInBill(this.formBill).then(response => {
              this.msgSuccess("新增成功");
              this.open_ = false;
              this.getBillList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDeleteBill(row) {
      const outInBillNos = row.outInBillNo || this.ids_;
      this.$confirm(
        '是否确认删除原料其他入库单管理编号为"' + outInBillNos + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delMaterialOutInBill(outInBillNos);
        })
        .then(() => {
          this.getBillList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryBillParams = this.queryBillParams;
      this.$confirm("是否确认导出所有原料其他入库单管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportMaterialOutInBill(queryBillParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    handleRowClick(row) {
      this.queryParams.outInBillNo = row.outInBillNo;
      this.queryParams.toString =
        "当前选中入库单号：" + this.queryParams.outInBillNo;
      this.getList();
    },
    /** 查询原料出入库订单明细管理列表 */
    getList() {
      this.loading = true;
      listMaterialOutInBilldetail(this.queryParams).then(response => {
        this.materialOutInBilldetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rowId: null,
        outInBillNo: this.queryParams.outInBillNo,
        barcode: null,
        materialNo: null,
        materialName: null,
        materialSpec: null,
        materialUnit: null,
        materialCategoryName: null,
        planNum: null,
        price: null,
        status: "02", //默认状态为进行中
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rowId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加原料其他入库单明细管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const rowId = row.rowId || this.ids;
      getMaterialOutInBilldetail(rowId).then(response => {
        this.form = response.data;
        this.form.materialUnit = this.materialUnitFormat(this.form);
        this.open = true;
        this.title = "修改原料其他入库单明细管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.rowId != null) {
            updateMaterialOutInBilldetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMaterialOutInBilldetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rowIds = row.rowId || this.ids;
      this.$confirm(
        '是否确认删除原料其他入库单明细管理编号为"' + rowIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delMaterialOutInBilldetail(rowIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有原料其他入库单明细管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportMaterialOutInBilldetail(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    selectMaterial() {
      this.openM = true;
    },
    handleSelectMaterial(data) {
      this.openM = false;
      this.form.materialNo = data.materialNo;
      this.form.materialName = data.materialName;
      this.form.materialSpec = data.materialSpec;
      this.form.materialCategoryName = data.materialCategoryName;
      this.form.materialUnit = data.materialUnit;
    },
    cancelSelectMaterial() {
      this.openM = false;
    }
  }
};
</script>
